package com.sunchen.asc.service.user.repository;

import com.sunchen.asc.service.user.domain.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface UserRepository extends JpaRepository<User,Long>, JpaSpecificationExecutor<User> {

    User findFirstByUserNameAndDeleteFlag(String userName,int deleteFlag);

    @Query("select t.userName from User t where t.id=?1")
    String findUserNameById(Long id);

    @Query("select t.name from User t where t.id in ?1 and t.deleteFlag = 0")
    List<String> findNameInIds(List<Long> userIds);

    @Query(value = "SELECT a.name from authentication a WHERE a.id in (SELECT t.authentications_id from role_authentications t WHERE t.role_id in ?1)",nativeQuery = true)
    List<String> findAuthByRoleIds(List<Long> collect);
}
